package com.zbkj.business.sys.examTask;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 卡任务列表
 * @create: 2025-05-11 12:49:19
 **/
@Service("examTask")
@Slf4j
public class ExamTaskService{

    @Resource
    ExamTaskDao examTaskDao;

    /**
     * 添加卡任务列表,获取id数据
     *
     * @param cdoRequest - id:编号
     *                   - task_title:标题
     *                   - task_charge:首充50/100
     *                   - task_commis:佣金
     *                   - task__url:开卡链接
     *                   - task__sign:标识
     *                   - task_notesa:备注
     *                   - task_notesb:备注
     *                   - task_notesc:备注
     *                   - created_at:添加时间
     *                   - updated_at:更新时间
     * @return
     * @author 
     * @create: 2025-05-11 12:49:19
     */
    @OpenApi
    public Return addExamTask(CDO cdoRequest) {
        examTaskDao.addExamTask(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新卡任务列表数据
     *
     * @param cdoRequest - id:编号
     *                   - task_title:标题
     *                   - task_charge:首充50/100
     *                   - task_commis:佣金
     *                   - task__url:开卡链接
     *                   - task__sign:标识
     *                   - task_notesa:备注
     *                   - task_notesb:备注
     *                   - task_notesc:备注
     *                   - created_at:添加时间
     *                   - updated_at:更新时间
     * @return
     * @author 
     * @create: 2025-05-11 12:49:19
     */
    @OpenApi
    public Return updateExamTaskById(CDO cdoRequest) {
        int affectedRows = examTaskDao.updateExamTaskById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除卡任务列表数据
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-05-11 12:49:19
     */
    //@OpenApi
    public Return deleteExamTaskById(CDO cdoRequest){
        int affectedRows = examTaskDao.deleteExamTaskById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除卡任务列表数据
     *
     * @param cdoRequest
     * @return
     * @author 
     * @create: 2025-05-11 12:49:19
     */
    //@OpenApi
    public Return deleteExamTask(CDO cdoRequest) {
        int affectedRows = examTaskDao.deleteExamTask(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取卡任务列表数据
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-05-11 12:49:19
     */
    @OpenApi
    public Return getExamTaskById(CDO cdoRequest) {
        CDO cdoMapperResult = examTaskDao.getExamTaskById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取卡任务列表数据
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-05-11 12:49:19
     */
    @OpenApi
    public Return getExamTask(CDO cdoRequest) {
        CDO cdoMapperResult = examTaskDao.getExamTask(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取卡任务列表数据列表
     *
     * @param cdoRequest
     * @return
     * @author 
     * @create: 2025-05-11 12:49:19
     */
    @OpenApi
    public Return getExamTaskList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = examTaskDao.getExamTaskList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = examTaskDao.getExamTaskListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取卡任务列表数据列表
     *
     * @param cdoRequest - id:编号
     * @return
     * @author 
     * @create: 2025-05-11 12:49:19
     */
    @OpenApi
    public Return getExamTaskListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = examTaskDao.getExamTaskListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = examTaskDao.getExamTaskListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
